package com.hzp.lolnews.ui.novel.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.hzp.lolnews.R;
import com.hzp.lolnews.ui.novel.bean.NavBean;
import com.hzp.lolnews.ui.novel.view.DetailWenActivity;

import java.util.List;

/**
 * Created by Administrator on 10/19 0019.
 */
public class NavAdapter  extends RecyclerView.Adapter<NavAdapter.MyViewHolder>{

    private List<NavBean.DataBean.TopicListBean.RowsBean> mList;
    private Context mContext;

    public NavAdapter(Context context) {

        mContext = context;
    }

    public void setData(List<NavBean.DataBean.TopicListBean.RowsBean> list) {
        this.mList = list;
        notifyDataSetChanged();
    }


    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.nav_list_item, parent, false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(final MyViewHolder holder, final int position) {
        final NavBean.DataBean.TopicListBean.RowsBean bean = mList.get(position);
        String nav_article_title = bean.getArticle_title();
        String nav_article_referrals = bean.getArticle_referrals();
        String nav_article_collection = bean.getArticle_collection();
        String nav_article_pic = bean.getArticle_pic();
        holder.nav_article_title.setText(nav_article_title);
        holder.nav_article_referrals.setText(nav_article_referrals);
        holder.nav_article_collection.setText(nav_article_collection);
        holder.nav_article_pic.setImageURI(nav_article_pic);
        holder.nav_article_pic.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(mContext, DetailWenActivity.class);
                intent.putExtra("getArticle_pic",bean.getArticle_pic());
                intent.putExtra("getArticle_type_name",bean.getArticle_type_name());
                intent.putExtra("getArticle_format_date",bean.getArticle_format_date());
                intent.putExtra("getArticle_title",bean.getArticle_title());
                intent.putExtra("getArticle_filter_content",bean.getArticle_filter_content());
                mContext.startActivity(intent);
            }
        });


    }

    @Override
    public int getItemCount() {
        return mList != null ? mList.size() : 0;
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        private TextView nav_article_title,nav_article_referrals,nav_article_collection;
        private SimpleDraweeView nav_article_pic;

        public MyViewHolder(View itemView) {
            super(itemView);
            nav_article_pic = (SimpleDraweeView) itemView.findViewById(R.id.nav_article_pic);
            nav_article_title = (TextView) itemView.findViewById(R.id.nav_article_title);
            nav_article_referrals = (TextView) itemView.findViewById(R.id.nav_article_referrals);
            nav_article_collection = (TextView) itemView.findViewById(R.id.nav_article_collection);
        }
    }
}
